package com.youlu.campus.admin.tencentcloud.service.impl;

import com.youlu.campus.admin.tencentcloud.entity.TencentCloudConfig;
import com.youlu.campus.admin.tencentcloud.repositories.TencentCloudConfigRepository;
import com.youlu.campus.admin.tencentcloud.service.TencentCloudConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 腾讯云 配置信息
 *
 * @Description: TencentCloudConfigService
 * @Date 2025/8/20
 * @module TencentCloudConfigService
 * @author: su
 */
@Slf4j
@Service
public class TencentCloudConfigServiceImpl implements TencentCloudConfigService {

    @Autowired
    private TencentCloudConfigRepository tencentCloudConfigRepository;

    /**
     * 保存
     *
     * @param config
     */
    @Override
    public void save(TencentCloudConfig config) {
        if (StringUtils.isNotBlank(config.getId())) {
            config.setUpdatedTime(new Date());
        } else {
            config.setCreatedTime(new Date());
        }
        tencentCloudConfigRepository.save(config);
    }


    @Override
    public List<TencentCloudConfig> findByType(String type) {
        return tencentCloudConfigRepository.findByType(type);
    }

    @Override
    public TencentCloudConfig findById(String configId) {
         return tencentCloudConfigRepository.findById(configId).orElse(null);
    }
}
